﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'SearchOrdenPedido')
	BEGIN
		DROP  Procedure  SearchOrdenPedido
	END

GO

CREATE Procedure SearchOrdenPedido

	(
		@fecha datetime
	)

AS

BEGIN
	SET NOCOUNT ON
	
	SELECT
	O.[Descripcion],
	O.[Estado],
	O.[FechaOrden],
	O.[IdEmpleado],
	O.[IdOrdenPedido],
	O.[IdPedido],
	O.[TipoOrdenPedido],
	P.[IdArea],
	A.[Nombre]
	FROM [OrdenPedido] AS O
	INNER JOIN [Pedido] AS P ON O.[IdPedido] = P.[IdPedido]
	INNER JOIN [Area] AS A ON P.[IdArea] = A.[IdArea]
	WHERE O.[FechaOrden] = @fecha
	ORDER BY O.[IdOrdenPedido] DESC

	SET NOCOUNT OFF
END

GO


GRANT EXEC ON SearchOrdenPedido TO PUBLIC

GO

